#!/bin/sh

if [ $# -lt 1 ]; then
    echo "no mount device specified"
    exit 1
fi

MNTPNT="1mnt"
if [ $# -gt 1 ]; then
    MNTPNT="$2"
fi

HOMESTAT="$(stat -c '%D' /home/"$USER")"
MOUNTSTAT="$(stat -c '%D' /home/"$USER"/"$MNTPNT")"
if [ "$MOUNTSTAT" != "$HOMESTAT" ]; then
    echo "target ~/$MNTPNT already mounted, unmount ~/mnt first"
    exit 1
fi

if [ $# -gt 2 ]; then
    if [ "$3" = "exfat" ]; then
        sudo mount.exfat -o uid=1000,gid=1000,umask=000 "$1" /home/"$USER"/"$MNTPNT"
        exit 1
    fi
fi

sudo mount "$1" /home/"$USER"/"$MNTPNT" -o uid=1000,gid=1000,umask=000